package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.GoodsOrder;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import com.alibaba.fastjson2.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/29 14:26
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class GoodsOrderVo extends BaseVO {
    /**
     * 订单编号
     */
    private String orderNo;

    /**
     * 商品id
     */
    private Long goodsId;

    /**
     * 商品名称
     */
    private String goodsName;

    /**
     * 商品分类
     */
    private String goodsCategory;

    /**
     * 商品价格
     */
    private String goodsPrice;

    private String goodsPic;

    /**
     * 购买人
     */
    private Long buyerId;

    /**
     * 购买人姓名
     */
    private String buyerName;

    private String buyerAvatar;

    private Long sellerId;

    private String sellerName;

    private String sellerAvatar;

    /**
     * 收货地址
     */
    private AddressVo address;

    /**
     * 支付状态，0未支付，1已支付，2已取消
     */
    private Integer payStatus;

    /**
     * 支付方式
     */
    private String payMethod;

    /**
     * 订单状态，0未完成，1已完成，2已取消
     */
    private Integer status;

    /**
     * 支付时间
     */
    private String payTime;

    /**
     * 成交时间
     */
    private String confirmTime;

    /**
     * 备注
     */
    private String remark;


    public static GoodsOrderVo convert(GoodsOrder goodsOrder) {
        if (goodsOrder == null) {
            return null;
        }
        GoodsOrderVo goodsOrderVo = new GoodsOrderVo();
        goodsOrderVo.setId(goodsOrder.getId());
        goodsOrderVo.setOrderNo(goodsOrder.getOrderNo());
        goodsOrderVo.setGoodsId(goodsOrder.getGoodsId());
        goodsOrderVo.setGoodsName(goodsOrder.getGoodsName());
        goodsOrderVo.setGoodsCategory(goodsOrder.getGoodsCategory());
        goodsOrderVo.setGoodsPrice(goodsOrder.getGoodsPrice().toString());
        if (goodsOrder.getGoodsPic() != null) {
            goodsOrderVo.setGoodsPic(goodsOrder.getGoodsPic().split(",")[0]);
        }
        goodsOrderVo.setBuyerId(goodsOrder.getBuyerId());
        goodsOrderVo.setBuyerName(goodsOrder.getBuyerName());
        goodsOrderVo.setBuyerAvatar(goodsOrder.getBuyerAvatar());
        goodsOrderVo.setSellerId(goodsOrder.getSellerId());
        goodsOrderVo.setSellerName(goodsOrder.getSellerName());
        goodsOrderVo.setSellerAvatar(goodsOrder.getSellerAvatar());
        goodsOrderVo.setAddress(JSON.parseObject(goodsOrder.getAddress(), AddressVo.class));
        goodsOrderVo.setPayStatus(goodsOrder.getPayStatus());
        goodsOrderVo.setPayMethod(goodsOrder.getPayMethod());
        goodsOrderVo.setStatus(goodsOrder.getStatus());
        goodsOrderVo.setPayTime(DateUtil.format(goodsOrder.getPayTime()));
        goodsOrderVo.setConfirmTime(DateUtil.format(goodsOrder.getConfirmTime()));
        goodsOrderVo.setRemark(goodsOrder.getRemark());
        goodsOrderVo.setCreateTime(DateUtil.format(goodsOrder.getCreateTime()));
        goodsOrderVo.setUpdateTime(DateUtil.format(goodsOrder.getUpdateTime()));
        return goodsOrderVo;
    }
}
